<template>
    <!-- 添加或修改设备维修保养对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="设备名称" prop="name">
                                <el-input v-model="form.name" placeholder="请输入设备名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备编码" prop="code">
                                <el-input v-model="form.code" placeholder="请输入设备编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备品牌" prop="pinpai">
                                <el-input v-model="form.pinpai" placeholder="请输入设备品牌"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="型号" prop="xinghao">
                                <el-input v-model="form.xinghao" placeholder="请输入型号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="所属部门" prop="haveHouse">
                                <el-input v-model="form.haveHouse" placeholder="请输入所属部门"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="其他文件">
                                <file-upload v-model="form.otherFile"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="维修/保养文件">
                                <file-copy-upload v-model="form.file"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="审核人" prop="shenheName">
                                <el-input v-model="form.shenheName" placeholder="请输入审核人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="使用部门" prop="useDept">
                                <el-input v-model="form.useDept" placeholder="请输入使用部门"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="故障问题" prop="problem">
                                <el-input v-model="form.problem" placeholder="请输入故障问题"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维保内容" prop="maintenance">
                                <el-input v-model="form.maintenance" placeholder="请输入维保内容"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维保金额" prop="money">
                                <el-input v-model="form.money" placeholder="请输入维保金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维保时间" prop="date">
                                <el-date-picker clearable
                                                v-model="form.date"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择维保时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维保记录" prop="record">
                                <el-input v-model="form.record" placeholder="请输入维保记录"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="维保人" prop="userName">
                                <el-input v-model="form.userName" placeholder="请输入维保人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="验收记录">
                                <editor v-model="form.checkContent" :min-height="192"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="验收人" prop="checkName">
                                <el-input v-model="form.checkName" placeholder="请输入验收人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="检修申请人" prop="jianxiuApply">
                                <el-input v-model="form.jianxiuApply" placeholder="请输入检修申请人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="检修记录" prop="jianxiuRecord">
                                <el-input v-model="form.jianxiuRecord" placeholder="请输入检修记录"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="检修人" prop="jianxiuName">
                                <el-input v-model="form.jianxiuName" placeholder="请输入检修人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="检修时间" prop="jianxiuDate">
                                <el-date-picker clearable
                                                v-model="form.jianxiuDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择检修时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="更换配件" prop="peijian">
                                <el-input v-model="form.peijian" placeholder="请输入更换配件"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="配件费" prop="peijianMoney">
                                <el-input v-model="form.peijianMoney" placeholder="请输入配件费"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合计金额" prop="allMoeny">
                                <el-input v-model="form.allMoeny" placeholder="请输入合计金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="车间主任" prop="director">
                                <el-input v-model="form.director" placeholder="请输入车间主任"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="主管领导" prop="leader">
                                <el-input v-model="form.leader" placeholder="请输入主管领导"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                          <el-form-item label="备注" prop="remark">
                            <el-input v-model="form.remark" placeholder="请输入备注"/>
                          </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "LnShebeiWeibaoForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/lnShebeiWeibao/lnShebeiWeibao/',
                    add:'/lnShebeiWeibao/lnShebeiWeibao/add',
                    edit:'/lnShebeiWeibao/lnShebeiWeibao/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
            delFlag: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            remark: null,
        status: "0",
            name: null,
            code: null,
            pinpai: null,
            xinghao: null,
            haveHouse: null,
            otherFile: null,
            file: null,
            type: null,
            shebeiType: null,
            shenheName: null,
            shenhestatus: "0",
            useDept: null,
            problem: null,
            problemType: null,
            maintenance: null,
            money: null,
            date: null,
            record: null,
            userName: null,
            checkContent: null,
            checkName: null,
            jianxiuApply: null,
            jianxiuRecord: null,
            jianxiuName: null,
            jianxiuDate: null,
            peijian: null,
            peijianMoney: null,
            allMoeny: null,
            director: null,
            leader: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加设备维修保养";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改设备维修保养";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
